import java.io.*;
import java.sql.*;
import java.util.*;

import local.util.MyPrint;

/************************************************************************
 * public Hashtable getTickIndustryName ();
 * pbulic Hashtable getTickSectorName   ();
 * public Hashtable getTickIndustryId   ();
 * public Hashtable getTickSectorId     ();
 * public String    getIndustryName     (String tick);
 * public String    getSectorName       (String tick);
 * public String    getIndustryId       (String tick);
 * public String    getSectorId         (String tick);
 ************************************************************************/

public class TickTable {

    private String dbDriverName    = "sun.jdbc.odbc.JdbcOdbcDriver";
    private String dataBaseName    = "jdbc:odbc:stock_record";
    private String userName        = "wli";
    private String password        = "4test";
    private String queryString     = "SELECT * FROM Tick";

    private Hashtable tickIndustryNameH = new Hashtable ();
    private Hashtable tickSectorNameH   = new Hashtable ();
    private Hashtable tickInsutryIdH    = new Hashtable ();
    private Hashtable tickSectorIdH     = new Hashtable ();

    public static void main (String args[]) {
	TickTable tb = new TickTable ();
	System.out.println(tb.getTickIndustryName("AMCC"));
    }

    public String getTickIndustryName ( String tick ) {
	String driverName   = dbDriverName;
	String dbURL        = dataBaseName;
	String theUser      = userName;
	String thePwd       = password;
	String query_string = "SELECT * FROM Tick WHERE Tick = '"+tick+"'";
	Hashtable tick_industry_name_h = new Hashtable ();

	try {
	    
	    Class.forName(driverName);
	    Connection con = DriverManager.getConnection(dbURL, theUser, thePwd);
	    Statement stmt = con.createStatement();
	    ResultSet res  = stmt.executeQuery(query_string);

	    while (res.next()){

		tick_industry_name_h.put(res.getString("Tick"), res.getString("Industry_Name"));
	    }

	    stmt.close();
	    
	} catch (java.lang.Exception ex) {
	    ex.printStackTrace();
	}

	return (String)(tick_industry_name_h.get(tick));
    }

    public Hashtable getTickIndustryName () {

	String driverName   = dbDriverName;
	String dbURL        = dataBaseName;
	String theUser      = userName;
	String thePwd       = password;
	String query_string = "SELECT * FROM Tick";
	Hashtable tick_industry_name_h = new Hashtable ();

	try {

	    Class.forName(driverName);
	    Connection con = DriverManager.getConnection(dbURL, theUser, thePwd);
	    Statement stmt = con.createStatement();
	    ResultSet res  = stmt.executeQuery(query_string);

	    while (res.next()){

		tick_industry_name_h.put(res.getString("Tick"), res.getString("Industry_Name"));
	    }

	    stmt.close();

	} catch (java.lang.Exception ex) {
	    ex.printStackTrace();
	}
	return tick_industry_name_h;
    }
}









